home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group97a.txt
/
000058_icon-group-sender _Mon Mar 3 12:31:17 1997.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
2KB
Received: by cheltenham.cs.arizona.edu; Mon, 3 Mar 1997 13:01:51 MST
Date: Mon, 3 Mar 1997 12:31:17 -0600
Message-Id: <199703031831.MAA09252@ns1.cmpu.net>
Mime-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
From: gep2@computek.net
Subject: Re: Help with Program
To: icon-group@cs.arizona.edu
X-Mailer: SPRY Mail Version: 04.00.06.17
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 1836
>> I thought about making something where you concatenate two consecutive lines
(in an overlapping pairs fashion) and then parse the two lines with a single
pattern match... eliminating the need to separately test the two category
numbers for equality, and eliminating all those "remember" assignments... but
finally decided that the way I did it was clearer and probably faster as well.
>That would have been an interesting solution to see!
It's really pretty simple, too (although my original was probably more
efficient):
&TRIM = 1
SWS = SPAN(" " CHAR(9)) ;* 'span whitespace' pattern
TAB = CHAR(9) ;* define a tab character
LET = ANY(&LCASE &UCASE) ;* parse an alpha character
RECPAT = SPAN("0123456789") $ N SWS LET . M1A SWS LET . M2A SWS
+ *N SWS LET . M1 SWS LET . M2 RPOS(0)
RLOOP (?(L1 = L) ?(LN1 = LN)) ;* remember prior line
L = INPUT ?(LN = LN + 1) :F(END) ;* read and count line
(L1 " " L) ? RECPAT :F(RLOOP) ;* parse line pair
OUTPUT = LN1 "-" LN TAB M1A M1 TAB M2A M2 :(RLOOP)
END
This version unfortunately requires that the number appear in EXACTLY the same
form, although that could be fixed by changing *N to:
SPAN("0123456789") $ N2 *EQ(N,N2)
The bigger problem is that (since now you have two reasons for the pattern to
fail... either the line doesn't parse, or else the lines don't match) and that
you basically both lose the diagnostic message for malformed lines, and you
change the way the two surrounding (presuming they're good) lines are handled.
One could make it less possible to "fool" the pattern match by appending
something trickier than a space between the records (a CR/LF pair might work,
for example) and changing the pattern appropriately.
Gordon Peterson
http://www.computek.net/public/gep2/